<template>
  <div class="xq-form-wrapper">
    <!-------------------------------------------- 表格区域区域start -------------------------------------------->
    <a-spin :spinning="spinning" class="xq-form-content">
      <XqTable
        :scroll="{ x: columns.length * 150 }"
        :pagination="false"
        :customize="FormJson['config']['table']['customize']"
        :dataSource="tableData"
        :columns="columns"
        :rowSelection="
          FormJson['config']['table']['extend']['batch']
            ? {
                selectedRowKeys: selectedRowKeys,
                onChange: onSelectChange
              }
            : null
        "
        class="xq-form-content-table"
      >
        <!--------------------------------------------主要内容，表格，自定义 header -------------------------------------------->
        <template v-for="(col, index) in columns" #[`xq_${col.dataIndex}`]>
          <span :key="index">
            {{ col.customTitle }}
          </span>
        </template>
        <!-------------------------------------------- 主要内容，表格，自定义 td -------------------------------------------->
        <template v-for="(col, index) in columns" #[col.dataIndex]="text, record">
          <!-------------------------------------------- 主操作列区域start -------------------------------------------->
          <span v-if="col.dataIndex === 'tableAction'" :key="index">
            <a @click="showUpdateModal(record)">编辑</a>
            <a-divider type="vertical" />
            <a-popconfirm :title="`确认要删除记录吗？`" okText="确认" cancelText="取消" @confirm="deleteRecord(record)">
              <a>删除</a>
            </a-popconfirm>
          </span>
          <!-------------------------------------------- 主操作列区域end -------------------------------------------->
          <!-------------------------------------------- 枚举值转换start -------------------------------------------->
          <XqTableCell v-else :key="index" :record="record" :field="FormJson['fields'][col.dataIndex]" :dynamicData="dynamicData" />
          <!-------------------------------------------- 枚举值转换end -------------------------------------------->
        </template>
      </XqTable>
      <!-------------------------------------------- 分页区域start -------------------------------------------->
      <div class="xq-form-content-pagination">
        <div class="xq-form-content-pagination-total">共 {{ total }} 条</div>
        <a-pagination
          v-model="currentPage"
          :pageSize="pageSize"
          :total="total"
          :showSizeChanger="true"
          :showQuickJumper="true"
          :page-size-options="['10', '20', '50', '100']"
          @change="onPageChange"
          @showSizeChange="onPageSizeChange"
        />
      </div>
      <!-------------------------------------------- 分页区域区域end -------------------------------------------->
    </a-spin>
    <!-------------------------------------------- 表格区域end -------------------------------------------->
  </div>
</template>
<script>
import FormJson from "./FormJson"; // 引入FormJson数据
import XqCurdMixin from "xqjr-plugin-form/mixins/XqCurdMixin";
import { retrieveReq } from "./api"; // 引入接口文件

const curdMixin = new XqCurdMixin({
  retrieveReq,
  FormJson,
  tableConfigKey: "table"
});

export default {
  props: {
    siteId: {
      type: String,
      default: undefined
    }
  },
  mixins: [curdMixin],
  data() {
    return {
      pageSize: 20
    };
  },
  computed: {
    retrieveParams() {
      return {
        request: {
          siteId: this.siteId
        }
      };
    },
    createParams() {
      return {};
    },
    updateParams() {
      return {};
    }
  },

  methods: {
    formatValues(values) {
      return values;
    },
    formatDataSource(record) {
      return record;
    }
  }
};
</script>
